package com.shadow.study.h2.controller;

import com.shadow.study.h2.entity.H2UserEntity;
import com.shadow.study.h2.service.H2UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("user")
public class H2UserController {

    @Resource
    private H2UserService userService;

    @GetMapping("add")
    public void add() {
        H2UserEntity user = new H2UserEntity();
        user.setUserName("1");
        user.setEmail("1");
        user.setPhone("1");
        user.setPassword("1");
        user.setCreateTime(LocalDateTime.now());
        userService.save(user);
    }

    @GetMapping("get")
    public List<H2UserEntity> get() {
        return userService.list();
    }
}
